package cn.sundat.web;


import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;

import cn.sundat.model.CompanyProduct;
import cn.sundat.model.Product;
import cn.sundat.service.CompanyProductService;
import cn.sundat.service.ProductService;
import cn.sundat.utils.FastJsonUtils;

public class ProductAction extends ActionSupport{
	private String cate_id;
	public void setCate_id(String cate_id) {
		this.cate_id = cate_id;
	}
	@Resource(name="companyProductService")
	private CompanyProductService cpService;
	
	@Resource(name="productService")
	private ProductService productService;
	
	public String findAll() {
		List<Product> list = productService.findAll();
		//查询公司已经添加的产品
		List<CompanyProduct> cplist = cpService.findPType(cate_id);
		//遍历，在集合中去掉已经添加的
		for (CompanyProduct cp : cplist) {
			list.remove(cp.getProduct());
		}
		String jsonString = FastJsonUtils.toJsonString(list);
		HttpServletResponse response = ServletActionContext.getResponse();
		FastJsonUtils.write_json(response, jsonString);
		
		return NONE;
	}
	
	public String findAllRemove() {
		List<Product> list = productService.findAll();
		return NONE;
	}
	
}
